package com.fattyCorps.config.gameConfig;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fattyCorps.an.AEventListener;
import com.fattyCorps.mapper.GlobalMouldMapper;
import com.fattyCorps.mgr.event.EEvent;
import com.fattyCorps.obj.mould.GlobalMould;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
public class GlobalConfig {

    private HashMap<String, String> globalConfigMap = new HashMap<>();

    public static final String STAR_LV = "star_lv";
    public static final String MAX_STAR = "max_star";
    public static final String ONE_LOTTERY_COIN = "one_lottery_coin";
    public static final String TEN_LOTTERY_COIN = "ten_lottery_coin";
    public static final String FREE_LOTTERY_TIME = "free_lottery_time";
    public static final String ONE_HERO_FRAGMENT_NUM = "one_hero_fragment_num";
    public static final String EXP_ITEM_TYPE_ID = "exp_item_type_id";
    public static final String STAR_STONE_ITEM_TYPE_ID = "star_stone_item_type_id";
    public static final String LOTTERY_ITEM_TYPE_ID = "lottery_item_type_id";

    public static final String PLAYER_INIT_ITEMS = "player_init_items";
    public static final String PLAYER_INIT_HEAD = "player_init_head";
    public static final String PLAYER_INIT_LV = "player_init_lv";
    public static final String PLAYER_INIT_COIN = "player_init_coin";
    public static final String PLAYER_INIT_GUANQIA = "player_init_guanqia";

    @Autowired
    GlobalMouldMapper globalMouldMapper;

    public String getStringValue(String name){
        return globalConfigMap.get(name);
    }

    public Integer getIntValue(String name){
        return Integer.valueOf(globalConfigMap.get(name));
    }

    @AEventListener(EEvent.EVENT_ON_SERVER_START)
    public void onServerStart() {
        QueryWrapper<GlobalMould> wrapper = new QueryWrapper<>();
        List<GlobalMould> globalMoulds = globalMouldMapper.selectList(wrapper);
        for (int i=0; i<globalMoulds.size(); i++){
            GlobalMould globalMould = globalMoulds.get(i);
            globalConfigMap.put(globalMould.getName(), globalMould.getValue());
        }
    }
}
